package com.lou.springboot.service.impl;

import com.lou.springboot.common.PageResult;
import com.lou.springboot.dao.BlogLinkDao;
import com.lou.springboot.entity.BlogLink;
import com.lou.springboot.service.BlogLinkService;
import com.lou.springboot.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogLinkServiceImpl implements BlogLinkService {

    @Autowired
    private BlogLinkDao linkDao;

    @Override
    public PageResult getBlogLinkPage(PageUtil pageUtil) {
        List<BlogLink> links = linkDao.findLinkList(pageUtil);
        int total = linkDao.getTotalLinks();
        return new PageResult(links, total, pageUtil.getLimit(), pageUtil.getPage());
    }

    @Override
    public boolean saveBlogLink(BlogLink blogLink) {
        return linkDao.insertBlogLink(blogLink) > 0;
    }

    @Override
    public boolean deleteBatch(Integer[] linkIds) {
        return linkDao.deleteBatch(linkIds) > 0;
    }

    @Override
    public BlogLink getBlogLinkById(Integer linkId) {
        return linkDao.selectByPrimaryKey(linkId);
    }

    @Override
    public boolean updateBlogLink(BlogLink blogLink) {
        return linkDao.updateLink(blogLink) > 0;
    }
}
